
package com.afd.ozblip.photo;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;

public final class PhotoIntentHelper {
    public static final String IMAGE_UNSPECIFIED = "image/*";

    public static final String IMAGE_JPEG = "image/jpeg";

    private static final int CONFIG_CROPIMAGE_USER_AVATAR_WIDTH = 192;

    private static final int CONFIG_CROPIMAGE_USER_AVATAR_HEIGHT = 192;

    // TODO 提取资源
    // private static final int CONFIG_CROPIMAGE_PETSHOW_PHOTO_WIDTH = 720;
    // private static final int CONFIG_CROPIMAGE_PETSHOW_PHOTO_HEIGHT = 720;

    // 选图片
    public static Intent getSelectImageIntent(Context context) {
        final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType(IMAGE_UNSPECIFIED);
        return Intent.createChooser(intent, null);
    }

    // 拍照
    public static Intent getCaptureImageIntent(Context context) {
        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT,
                TempFileProvider.CONTENT_URI_CAPTURE_IMAGE);
        return Intent.createChooser(intent, null);
    }

    // 裁剪车头像
    public static Intent getCropCarAvatarIntent(Context context, Uri dataUri,
            Uri outputUri) {
        return getCropUserAvatarIntent(context, dataUri, outputUri);
    }

    // 裁剪用户头像
    public static Intent getCropUserAvatarIntent(Context context, Uri dataUri,
            Uri outputUri) {
        final Intent intent = new Intent(context, CropImageActivity.class);

        // 要裁剪的图片的Uri
        intent.setData(dataUri);
        // 保存裁剪后图片的Uri
        intent.putExtra(CropImageActivity.EXTRA_OUTPUT, outputUri);
        // 保存格式JPEG
        intent.putExtra(CropImageActivity.EXTRA_OUTPUT_FORMAT,
                Bitmap.CompressFormat.JPEG.name());
        // 不启用脸部识别
        intent.putExtra(CropImageActivity.EXTRA_NO_FACE_DETECTION, true);
        // 横竖比例1:1
        intent.putExtra(CropImageActivity.EXTRA_ASPECT_X,
                CONFIG_CROPIMAGE_USER_AVATAR_WIDTH);
        intent.putExtra(CropImageActivity.EXTRA_ASPECT_Y,
                CONFIG_CROPIMAGE_USER_AVATAR_HEIGHT);
        // 输出尺寸
        intent.putExtra(CropImageActivity.EXTRA_OUTPUT_X,
                CONFIG_CROPIMAGE_USER_AVATAR_WIDTH);
        intent.putExtra(CropImageActivity.EXTRA_OUTPUT_Y,
                CONFIG_CROPIMAGE_USER_AVATAR_HEIGHT);
        // 缩放到输出尺寸
        intent.putExtra(CropImageActivity.EXTRA_SCALE, true);
        // 小于输出尺寸放大到输出尺寸
        intent.putExtra(CropImageActivity.EXTRA_SCALE_UP_IF_NEEDED, true);

        return intent;
    }

    // // 裁剪宠物秀照片
    // public static Intent getCropPetshowPhotoIntent(Context context,
    // Uri dataUri, Uri outputUri) {
    // final Intent intent = new Intent(context, CropImageActivity.class);
    //
    // // 要裁剪的图片的Uri
    // intent.setData(dataUri);
    // // 保存裁剪后图片的Uri
    // intent.putExtra(CropImageActivity.EXTRA_OUTPUT, outputUri);
    // // 保存格式JPEG
    // intent.putExtra(CropImageActivity.EXTRA_OUTPUT_FORMAT,
    // Bitmap.CompressFormat.JPEG.name());
    // // 不启用脸部识别
    // intent.putExtra(CropImageActivity.EXTRA_NO_FACE_DETECTION, true);
    // // 横竖比例1:1
    // intent.putExtra(CropImageActivity.EXTRA_ASPECT_X,
    // CONFIG_CROPIMAGE_PETSHOW_PHOTO_WIDTH);
    // intent.putExtra(CropImageActivity.EXTRA_ASPECT_Y,
    // CONFIG_CROPIMAGE_PETSHOW_PHOTO_HEIGHT);
    // // 输出尺寸
    // intent.putExtra(CropImageActivity.EXTRA_OUTPUT_X,
    // CONFIG_CROPIMAGE_PETSHOW_PHOTO_WIDTH);
    // intent.putExtra(CropImageActivity.EXTRA_OUTPUT_Y,
    // CONFIG_CROPIMAGE_PETSHOW_PHOTO_HEIGHT);
    // // 缩放到输出尺寸
    // intent.putExtra(CropImageActivity.EXTRA_SCALE, true);
    // // 小于输出尺寸放大到输出尺寸
    // intent.putExtra(CropImageActivity.EXTRA_SCALE_UP_IF_NEEDED, true);
    //
    // return intent;
    // }
}
